package com.youcheng.config.rabbit;

import com.youcheng.utils.Constants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfigRouting {

    @Bean
    public Queue youA(){
        return new Queue("youA");
    }

    @Bean
    public Queue youB(){
        return new Queue("youB");
    }

    //创建一个direct交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("youExchange");
    }

    //将queueA队列绑定到directExchange交换机中，使用direct.a.key作为路由规则
    @Bean
    public Binding bindingExchangeMessageDirectA(Queue youA, DirectExchange directExchange) {
        return BindingBuilder.bind(youA).to(directExchange).with("direct.a.key");
    }

    //将queueB队列绑定到directExchange交换机中，使用direct.a.key作为路由规则
    @Bean
    public Binding bindingExchangeMessageDirectB(Queue youB, DirectExchange directExchange) {
        return BindingBuilder.bind(youB).to(directExchange).with("direct.b.key");
    }

}
